// Cloud Functions Example
resource "google_compute_region_network_endpoint_group" "<%= ctx[:primary_resource_id] %>" {
  name                  = "<%= ctx[:vars]['neg_name'] %>"
  network_endpoint_type = "SERVERLESS"
  region                = "us-central1"
  cloud_function {
    function = google_cloudfunctions_function.<%= ctx[:primary_resource_id] %>.name
  }
}

resource "google_cloudfunctions_function" "<%= ctx[:primary_resource_id] %>" {
  name        = "<%= ctx[:vars]['neg_name'] %>"
  description = "My function"
  runtime     = "nodejs10"

  available_memory_mb   = 128
  source_archive_bucket = google_storage_bucket.bucket.name
  source_archive_object = google_storage_bucket_object.archive.name
  trigger_http          = true
  timeout               = 60
  entry_point           = "helloGET"
}

resource "google_storage_bucket" "bucket" {
  name       = "<%= ctx[:vars]['bucket_name'] %>"
}

resource "google_storage_bucket_object" "archive" { 
  name       = "index.zip"
  bucket     = google_storage_bucket.bucket.name
  source     = "<%= ctx[:vars]['zip_path'] %>"
}